package com.wanxi.service.impl;

import com.wanxi.dao.CompanyDao;
import com.wanxi.dao.impl.CompanyDaoImpl;
import com.wanxi.dto.CompanyDTO;
import com.wanxi.service.CompanyService;
import com.wanxi.util.Tool;
import redis.clients.jedis.Jedis;

public class CompanyServiceImpl implements CompanyService {
    private CompanyDao companyDao = new CompanyDaoImpl();

    /**
     * *      List<ProductModel> list=null;
     * *      for(int i=0;i<10000;i++){
     * *          if(i==0){
     * *              list=productDao.findAll();
     * *          }else{
     * *              list=redisData();
     * *          }
     * *      }
     *
     * @return
     */
    @Override
    public CompanyDTO getData() {
        CompanyDTO companyDTO = new CompanyDTO();
        Jedis jedis = new Jedis();
        //数据类型为String的，如果第二次存，则覆盖以前的数据
        boolean isHave = jedis.exists("logo");
        if (isHave) {
            companyDTO.setLogo(jedis.get("logo"));
            companyDTO.setPhone(jedis.get("phone"));
            companyDTO.setNet(jedis.get("net"));
            companyDTO.setEmail(jedis.get("email"));
            companyDTO.setAddress(jedis.get("address"));
            companyDTO.setLinePhone(jedis.get("linePhone"));
            companyDTO.setVersion(jedis.get("version"));
        } else {
            companyDTO = Tool.copy(companyDao.getCompanyModel(), CompanyDTO.class);
            jedis.set("logo", companyDTO.getLogo());
            jedis.set("phone", companyDTO.getPhone());
            jedis.set("net", companyDTO.getNet());
            jedis.set("email", companyDTO.getEmail());
            jedis.set("address", companyDTO.getAddress());
            jedis.set("version", companyDTO.getVersion());
            jedis.set("linePhone", companyDTO.getLinePhone());
        }
        return companyDTO;
    }
}
